package com.wgzx.modbus.entity.request;

import com.wgzx.modbus.entity.ModbusReq;

import static com.wgzx.modbus.constant.FunctionCode.WRITE_SINGLE_COIL;
import static com.wgzx.modbus.util.ModbusUtil.validateRange;

/**
 * 写单个线圈 <br/>
 * 功能码：0x05 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 输出值：2个字节0x0000或0xFF00 <br/>
 *
 * @author gexin
 */
public class WriteSingleCoilRequest extends ModbusReq {

    private boolean state;

    public WriteSingleCoilRequest(int outputAddress, boolean state) {
        super(WRITE_SINGLE_COIL, outputAddress, state ? 0xFF00 : 0x0000);
        validateRange(outputAddress, "outputAddress", 0x00, 0xFFFF);
        this.state = state;
    }

    @Override
    public String toString() {
        return "WriteSingleCoil{" + "outputAddress=" + address + ", state=" + state + '}';
    }
}
